package com.example.tang.zhayan.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by yang on 2015/12/16.
 */
public class DesignerPagerAdapter extends PagerAdapter {

    private List<View> list;
    private SetPageClick click;

    public SetPageClick getClick() {
        return click;
    }

    public void setClick(SetPageClick click) {
        this.click = click;
    }

    public DesignerPagerAdapter(List<View> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return object==view;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
       View v= list.get(position);
        container.addView(v);
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                click.setOnPageClick(position);
            }
        });
        return v;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
       container.removeView(list.get(position));
    }

    public interface SetPageClick{
      void setOnPageClick(int position);
    }
}
